<?php

  include "DALcustomerEnquiryProblem.php";

  function validateDetails($staff_no, $enquiry_date, $prod_no, $description, $quantity, $reason, $dep_no, $customer_name, 
  $customer_no)
  {
    if($staff_no == "" /*|| $enquiry_date == "" */|| ($prod_no == "" && $description == "") || $quantity == "" || $reason == "" || 
	$dep_no == "" || 
        empty($staff_no) /*|| empty($enquiry_date) */|| (empty($prod_no) || empty($description)) || empty($quantity))
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('You must enter details in all mandatory fields.');";
      echo "</SCRIPT>";
      return false;
    }
/*
	else if(isNumber($staff_no) == false)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('The staff number must be numeric.');";
      echo "</SCRIPT>";
      return false;
    }
	else if(strlen($staff_no) != 5)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('The staff number should be 5 digits.');";
      echo "</SCRIPT>";
      return false;
    }
*/
	else if(checkEnteredStaffNo($staff_no) == false)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('Please enter registered staff number.');";
      echo "</SCRIPT>";
      return false;
    }

/*
    else if(isNumber($prod_no) == false)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('The product number must be numeric.');";
      echo "</SCRIPT>";
      return false;
    }
	else if(strlen($prod_no) != 5)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('The product number should be five digits.');";
      echo "</SCRIPT>";
      return false;
    }
*/
	else if(checkEnteredProductNo($prod_no) == false)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('Please enter valid product number.');";
      echo "</SCRIPT>";
      return false;
    }
    else if(isNumber($quantity) == false)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('The quantity must be numeric.');";
      echo "</SCRIPT>";
      return false;
    }
/*
	else if(strlen($customer_name) > 30 || strlen($customer_no) != 5 || isNumber($customer_no) == false)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('The customer name must be less than 30 characters and the customer number must be 5 digits.');";
      echo "</SCRIPT>";
      return false;
    }
*/
	else if(checkEnteredCustomerNo($customer_no) == false || checkEnteredCustomerName($customer_name) == false)
    {
	  echo "<SCRIPT language='Javascript'>";
      echo "  alert('Please enter valid customer details.');";
      echo "</SCRIPT>";
      return false;
    }
	else
	{
      echo "<SCRIPT language='Javascript'>"; 
      echo "  alert('yesssssssssss');"; 
      echo "</SCRIPT>"; 
      return true; 
	}
  }

  //records new details of a customer enquiry problem
  function recordProblem($staff_no, $enquiry_date, $prod_no, $description, $quantity, $reason, $dep_no, $customer_name, 
  $customer_no)

  {
      return insertProblem($staff_no, $enquiry_date, $prod_no, $description, $quantity, $reason, $dep_no, $customer_name, 
      $customer_no);

  }

  function checkEnteredProductNo($prod_no)
  {
	  return checkValidProductNo($prod_no);
  }

  function checkEnteredStaffNo($staff_no)
  {
	  return checkValidStaffNo($staff_no);
  }

  function checkEnteredCustomerName($customer_name)
  {
	  return checkValidCustomerName($customer_name);
  }

  function checkEneterdCustomerNo($customer_no)
  {
	  return checkValidCustomerNo($customer_no);
  }

  function isNumber($number)
  {
    for($i = 0; $i < strlen($number); $i++)
    {
	  $n = $number[$i];
      if($n == '0' || $n == '1' || $n == '2' || $n == '3' || $n == '4' || $n == '5' || $n == '6' || $n == '7' || $n == '8' || $n == '9')
	  {
	  }
	  else
      {
        return false;
      }
    }
    return true;
  }


?>